<template>
    <div class="charging-set">
        <!-- 筛选条件 -->
        <condition-card @search="filterCondition" @reset="reset" label-width="130px">
            <el-row>
                <el-col :span="8">
                    <el-form-item label="缴费条件简称">
                        <el-input style="width: 100%;" v-model="query.payConditionName"></el-input>
                        <!-- <el-select
                            style="width: 100%;"
                            v-model="query.payConditionId"
                            filterable
                            remote
                            clearable
                            reserve-keyword
                            @change="clearOptions"
                            placeholder="请输入缴费条件简称"
                            :remote-method="getPayConditionName"
                            :loading="loading"
                        >
                            <el-option
                                v-for="item in options.payConditionId"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select> -->
                        
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="年级">
                        <el-date-picker
                            style="width: 100%;"
                            v-model="query.grade"
                            type="year"
                            value-format="yyyy"
                            placeholder="请选择"
                            :picker-options="pickerOptions"
                            @change="currentManageDptId === '1' ? handleChangeFaculty() : ''"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学院">
                        <DictSelect
                            labelAll="请选择"
                            v-model="multipleQuery.faculty"
                            :data="options.faculty"
                            multiple
                            @change="handleChangeFaculty"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="专业">
                        <DictSelect
                            labelAll="请选择"
                            v-model="multipleQuery.profession"
                            multiple
                            :data="options.profession"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="培养层次">
                        <DictSelect
                            labelAll="请选择"
                            v-model="multipleQuery.trainingLevel"
                            :data="options.trainingLevel"
                            multiple="true"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="培养类别">
                        <DictSelect
                            labelAll="请选择"
                            v-model="multipleQuery.trainingCategory"
                            :data="options.trainingCategory"
                            multiple="true"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学位类型">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.degreeType"
                            :data="options.degreeType"
                            @change="currentManageDptId !== '1' ? handleChangeFaculty() : ''"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学习形式">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.formLearning"
                            :data="options.formLearning"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学制">
                        <DictSelect
                            labelAll="请选择"
                            v-model="multipleQuery.lengthSchooling"
                            :data="options.lengthSchooling"
                            multiple="true"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
            </el-row>
        </condition-card>
        <el-card shadow="never">
            <h2>在校应收费名单列表</h2>
            <el-row type="flex" align="middle" class="mb-8px">
                <el-col class="text-right" v-if="currentUid !== 'admin1'">
                    <el-button @click="initList">初始化名单</el-button>
                    <el-button @click="copyCharging">复制</el-button>
                    <el-button type="primary" @click="addCharging">新增</el-button>
                </el-col>
            </el-row>
            <edu-table
                ref="chargingTable"
                :order="false"
                :pageNum="query.pageNum_"
                :data="chargingList.data"
                :total="chargingList.total"
                @page-change="pageChange"
                @selection-change="handleSelectionChange"
            >
                <el-table-column label="缴费条件简称" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.payConditionName}}</template>
                </el-table-column>
                <el-table-column label="年级" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.grade}}</template>
                </el-table-column>
                <el-table-column label="学院" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.facultyI18n}}</template>
                </el-table-column>
                <el-table-column label="专业" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.professionI18n}}</template>
                </el-table-column>
                <el-table-column label="培养层次">
                    <template slot-scope="scope">{{scope.row.trainingLevelI18n}}</template>
                </el-table-column>
                <el-table-column label="培养类别">
                    <template slot-scope="scope">{{scope.row.trainingCategoryI18n}}</template>
                </el-table-column>
                <el-table-column label="学制">
                    <template slot-scope="scope">{{scope.row.lengthSchoolingI18n}}</template>
                </el-table-column>
                <el-table-column label="学位类型">
                    <template slot-scope="scope">{{scope.row.degreeTypeI18n}}</template>
                </el-table-column>
                <el-table-column label="学习形式">
                    <template slot-scope="scope">{{scope.row.formLearningI18n}}</template>
                </el-table-column>
                <el-table-column label="总应缴费用">
                    <template slot-scope="scope">{{scope.row.sum}}</template>
                </el-table-column>
                <el-table-column label="操作" v-if="currentUid !== 'admin1'">
                    <template slot-scope="scope">
                        <el-button type="text" @click="editCharging(scope.row)">编辑</el-button>
                        <el-button type="text" @click="deleteCharging(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </edu-table>
        </el-card>
        <!-- 新增、编辑界面 -->
        <edu-dialog
            ref="setDialog"
            title="在校应收费设置维护"
            size="medium"
            @close="closeSetDialog"
            :auto-height="true"
        >
            <el-form
                ref="setDialogForm"
                label-position="right"
                label-width="130px"
                :rules="setDialog.rules"
                :model="setDialog.form"
            >
                <p>基础信息</p>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="缴费条件简称:" prop="payConditionName">
                            <el-input
                                type="text"
                                v-model="setDialog.form.payConditionName"
                                placeholder="请输入缴费条件简称"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="年级:" prop="grade">
                            <el-date-picker
                                style="width: 100%;"
                                v-model="setDialog.form.grade"
                                type="year"
                                value-format="yyyy"
                                placeholder="请选择"
                                :picker-options="pickerOptions"
                                @change="currentManageDptId === '1' ? handleChangeFaculty() : ''"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学院:" prop="faculty">
                            <DictSelect
                                v-model="setDialog.form.faculty"
                                :data="options.faculty"
                                @change="handleChangeFaculty(setDialog.form.faculty, 'add')"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="专业:" prop="profession">
                            <DictSelect
                                v-model="setDialog.professionFrom"
                                multiple
                                :data="setDialog.profession"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="培养层次:" prop="trainingLevel">
                            <DictSelect
                                v-model="setDialog.form.trainingLevel"
                                :data="options.trainingLevel"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="培养类别:" prop="trainingCategory">
                            <DictSelect
                                v-model="setDialog.form.trainingCategory"
                                :data="options.trainingCategory"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学位类型:" prop="degreeType">
                            <DictSelect
                                v-model="setDialog.form.degreeType"
                                :data="options.degreeType"
                                @change="currentManageDptId !== '1' ? handleChangeFaculty() : ''"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学习形式:" prop="formLearning">
                            <DictSelect
                                v-model="setDialog.form.formLearning"
                                :data="options.formLearning"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学制:" prop="lengthSchooling">
                            <DictSelect
                                v-model="setDialog.form.lengthSchooling"
                                :data="options.lengthSchooling" @change="changeClick"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <p>学年应缴费用信息设置</p>
                <el-row>
                    <el-col>
                        <el-form-item label="总应缴费用:" prop="sum">
                            <el-input type="text" v-model.number="setDialog.form.sum" disabled></el-input>
                        </el-form-item>
                    </el-col>
                    <template v-if="setDialog.form.lengthSchooling">
                        <el-col :span="12" v-if="0.5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第一学年第1学期"
                                prop="semester1"
                                :rules="[
                                { required: true, message: '费用不能为空'},
                                { type: 'number', message: '费用必须为数字'}
                            ] "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester1"
                                    :precision="2"
                                    :step="0.1"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="1 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第一学年第2学期"
                                prop="semester2"
                                :rules="setDialog.projId !== '1' ? [
                                { type: 'number', message: '费用必须为数字'}
                            ] : '' "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester2"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="1.5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第二学年第1学期"
                                prop="semester3"
                                :rules="[
                                { required: true, message: '费用不能为空'},
                                { type: 'number', message: '费用必须为数字'}
                            ] "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester3"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="2 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第二学年第2学期"
                                prop="semester4"
                                :rules="setDialog.projId !== '1' ? [
                                { type: 'number', message: '费用必须为数字'}
                            ] : '' "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester4"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="2.5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第三学年第1学期"
                                prop="semester5"
                                :rules="[
                                { required: true, message: '费用不能为空'},
                                { type: 'number', message: '费用必须为数字'}
                            ] "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester5"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="3 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第三学年第2学期"
                                prop="semester6"
                                :rules="setDialog.projId !== '1' ? [
                                { type: 'number', message: '费用必须为数字'}
                            ] : '' "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester6"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="3.5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第四学年第1学期"
                                prop="semester7"
                                :rules="[
                                { required: true, message: '费用不能为空'},
                                { type: 'number', message: '费用必须为数字'}
                            ] "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester7"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="4 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第四学年第2学期"
                                prop="semester8"
                                :rules="setDialog.projId !== '1' ? [
                                { type: 'number', message: '费用必须为数字'}
                            ] : '' "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester8"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="4.5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第五学年第1学期"
                                prop="semester9"
                                :rules="[
                                { required: true, message: '费用不能为空'},
                                { type: 'number', message: '费用必须为数字'}
                            ] "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester9"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第五学年第2学期"
                                prop="semester10"
                                :rules="setDialog.projId !== '1' ? [
                                { type: 'number', message: '费用必须为数字'}
                            ] : ''"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester10"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="5.5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第六学年第1学期"
                                prop="semester11"
                                :rules="[
                                { required: true, message: '费用不能为空'},
                                { type: 'number', message: '费用必须为数字'}
                            ] "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester11"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="6 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第六学年第2学期"
                                prop="semester12"
                                :rules="setDialog.projId !== '1' ? [
                                { type: 'number', message: '费用必须为数字'}
                            ] : '' "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester12"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="6.5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第七学年第1学期"
                                prop="semester13"
                                :rules="[
                                { required: true, message: '费用不能为空'},
                                { type: 'number', message: '费用必须为数字'}
                            ] "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester13"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="7 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第七学年第2学期"
                                prop="semester14"
                                :rules="setDialog.projId !== '1' ? [
                                { type: 'number', message: '费用必须为数字'}
                            ] : '' "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester14"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="7.5 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第八学年第1学期"
                                prop="semester15"
                                :rules="[
                                { required: true, message: '费用不能为空'},
                                { type: 'number', message: '费用必须为数字'}
                            ] "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester15"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="8 <= setDialog.form.lengthSchooling">
                            <el-form-item
                                label="第八学年第2学期"
                                prop="semester16"
                                :rules="setDialog.projId !== '1' ? [
                                { type: 'number', message: '费用必须为数字'}
                            ] : '' "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="setDialog.form.semester16"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                    </template>
                </el-row>
            </el-form>
            <edu-dialog ref="hintDialog" title="提示" class="tip-item" append-to-body>
                返回将不会保存当前应收费设置，是否确定？
                <span slot="buttons">
                    <el-button @click="cancleDialog">取消</el-button>
                    <el-button type="primary" @click="confirmDialog">确定</el-button>
                    <el-button type="primary" @click="confirmAndSave">保存并关闭</el-button>
                </span>
            </edu-dialog>
            <span slot="buttons">
                <el-button @click="cancleSetDialog">返回</el-button>
                <el-button type="primary" @click="saveSetDialog">保存</el-button>
            </span>
        </edu-dialog>
        <!-- 删除提示 -->
        <edu-dialog ref="deleteDialog" class="tip-item" title="提示">
            是否确认删除？
            <span slot="buttons">
                <el-button @click="cancleDelete">取消</el-button>
                <el-button type="primary" @click="confirmDelete">确定</el-button>
            </span>
        </edu-dialog>
    </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import * as API from "common/src/api/paymentManage";
export default {
    name: "paymentListMaintain",
    components: {},
    data() {
        return {
            multipleQuery: {
                faculty: [],
                profession: [],
                trainingLevel: [],
                trainingCategory: [],
                lengthSchooling: []
            },
            query: {
                payConditionId: "",
                payConditionName: "",
                grade: "",
                faculty: "",
                profession: "",
                trainingLevel: "",
                trainingCategory: "",
                degreeType: "",
                formLearning: "",
                lengthSchooling: "",
                pageNum_: 1,
                pageSize_: 20
            },
            options: {
                payConditionId: [],
                faculty: [],
                profession: [],
                trainingLevel: [],
                formLearning: [],
                degreeType: [],
                trainingCategory: [],
                lengthSchooling: []
            },
            chargingList: {
                total: 0,
                data: [],
                selectItems: []
            },
            maintainForm: {},
            pickerOptions: {
                disabledDate(time) {
                    return (
                        time.getTime() > Date.now() ||
                        time.getTime() < new Date("1978").getTime()
                    );
                }
            },
            setDialog: {
                form: {
                    payConditionName: "",
                    grade: "",
                    type: "", // 标识编辑、新增、复制（0：编辑，空：新增、复制）
                    faculty: "",
                    profession: [],
                    trainingLevel: "",
                    trainingCategory: "",
                    degreeType: "",
                    formLearning: "",
                    lengthSchooling: "",
                    sum: "",
                    semester1: null,
                    semester2: null,
                    semester3: null,
                    semester4: null,
                    semester5: null,
                    semester6: null,
                    semester7: null,
                    semester8: null,
                    semester9: null,
                    semester10: null,
                    semester11: null,
                    semester12: null,
                    semester13: null,
                    semester14: null,
                    semester15: null,
                    semester16: null
                },
                projId: null,
                professionFrom: [],
                semesterArr: [],
                profession: [],
                type: null,
                rules: {
                    payConditionName: [
                        {
                            required: true,
                            message: "请输入缴费条件简称",
                            trigger: "blur"
                        }
                    ],
                    grade: [
                        {
                            required: true,
                            message: "请选择年级",
                            trigger: "change"
                        }
                    ],
                    trainingLevel: [
                        {
                            required: true,
                            message: "请选择培养层次",
                            trigger: "change"
                        }
                    ],
                    trainingCategory: [
                        {
                            required: true,
                            message: "请选择培养类别",
                            trigger: "change"
                        }
                    ],
                    degreeType: [
                        {
                            required: true,
                            message: "请选择学位类型",
                            trigger: "change"
                        }
                    ],
                    formLearning: [
                        {
                            required: true,
                            message: "请选择学习形式",
                            trigger: "change"
                        }
                    ],
                    lengthSchooling: [
                        {
                            required: true,
                            message: "请选择学制",
                            trigger: "change"
                        }
                    ]
                }
            },
            deleteDialog: {
                data: null
            },
            currentManageDptId: "", // 当前部门
            currentUid: "" // 当前uid
        };
    },
    created() {
        this.initOptions();
        this.getChargingSetList();
        // 获取当前部门和当前uid
        if (this.mockUser) {
            this.currentManageDptId = this.mockUser.currentManageDptId;
            this.currentUid = this.mockUser.uid;
        } else {
            this.currentManageDptId = this.currentUser.currentManageDptId;
            this.currentUid = this.currentUser.uid;
        }
    },
    mounted() {},
    methods: {
        // 获取筛选条件字段下拉数据
        initOptions() {
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: [
                    "X_YX",
                    "X_PYCC",
                    "X_XWLX",
                    "X_PYLB",
                    "X_XXXS",
                    "X_XZ",
                    "K_ZXZT"
                ]
            };
            queryDic(data).then(res => {
                if (res.code === 200 && res.data) {
                    UTILS.fillSelect(
                        {
                            faculty: "X_YX",
                            trainingLevel: "X_PYCC",
                            trainingCategory: "X_PYLB",
                            degreeType: "X_XWLX",
                            formLearning: "X_XXXS",
                            lengthSchooling: "X_XZ",
                            leaveSchool: "K_ZXZT"
                        },
                        res.data,
                        this.options
                    );

                this.options.lengthSchooling.sort(function(a, b){return a.value - b.value})
                // console.log(this.options.lengthSchooling, 'dd', list);
                }
            });
        },
        // 根据学院获取专业
        handleChangeFaculty(val, type) {
            this.options.profession = [];
            this.query.profession = "";
            this.setDialog.profession = [];
            this.setDialog.professionFrom = [];
            let facultys, degreeType;
            type = type || this.setDialog.type;
            if (
                (type && type === "edit") ||
                type === "add" ||
                type === "copy"
            ) {
                let maintainFaculty = this.setDialog.form.faculty;
                let maintainDegreeType = this.setDialog.form.degreeType;
                facultys = maintainFaculty ? [maintainFaculty] : [];
                degreeType = maintainDegreeType ? [maintainDegreeType] : [];
            } else {
                facultys = this.multipleQuery.faculty;
                degreeType = this.query.degreeType
                    ? [this.query.degreeType]
                    : [];
            }
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["G_ZY"],
                filter: {
                    prefix: facultys,
                    specilaCode: "XY2ZY",
                    facultys: facultys,
                    grade: this.query.grade,
                    degreeType: degreeType
                }
            };
            queryDic(data).then(res => {
                if (res.code === 200 && res.data)
                    UTILS.fillSelect(
                        {
                            profession: "G_ZY"
                        },
                        res.data,
                        this.options
                    );
                if (
                    (type && type === "edit") ||
                    type === "add" ||
                    type === "copy"
                ) {
                    UTILS.fillSelect(
                        {
                            profession: "G_ZY"
                        },
                        res.data,
                        this.setDialog
                    );
                }
            });
        },
        // 点击新增  打开新增编辑弹窗
        addCharging() {
            this.$refs.setDialog.open();
            this.setDialog.type = "add";
            this.setDialog.projId = this.currentManageDptId;
        },
        // 关闭setDialog弹窗 初始化数据
        closeSetDialog() {
            // 重置表单信息数据
            this.$refs.setDialogForm.resetFields();
            let setDialogForm = this.setDialog.form;
            for (var key in setDialogForm) {
                if (key.includes("semester")) {
                    setDialogForm[key] = null;
                } else if (
                    key.includes("ids") ||
                    key.includes("payConditionId")
                ) {
                    delete setDialogForm[key];
                } else {
                    setDialogForm[key] = "";
                }
            }
            this.setDialog.professionFrom = [];
            this.setDialog.profession = [];
            this.setDialog.type = null;
            this.setDialog.projId = null;
        },
        // 点击返回按钮  校验是否填写数据
        cancleSetDialog() {
            // 判断setDialog.form是否有值
            let formData = this.setDialog.form;
            let keys = Object.keys(formData).filter(item => {
                return formData[item];
            });
            let length = keys.length;
            let professionLength = this.setDialog.professionFrom.length;
            if (length || professionLength) {
                this.$refs.hintDialog.open();
            } else {
                this.$refs.setDialog.close();
            }
        },
        // 关闭setDialog 弹窗 并保存数据（调取新增和编辑接口）
        saveSetDialog() {
            // 保存数据操作
            this.getSum()
            this.setDialog.form.profession = this.setDialog.professionFrom.join(",");
            this.$refs.setDialogForm.validate(valid => {
                if (valid) {
                    if (
                        this.setDialog.type === "add" ||
                        this.setDialog.type === "copy"
                    )
                        API.addPayConfig(this.setDialog.form).then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: "success",
                                    message: "新增成功！"
                                });
                                this.getChargingSetList();
                                this.$refs.setDialog.close();
                                this.$refs.hintDialog.close();
                            }
                        });
                    else if (this.setDialog.type === "edit")
                        API.editPayConfig(this.setDialog.form).then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: "success",
                                    message: "编辑成功！"
                                });
                                this.getChargingSetList();
                                this.$refs.setDialog.close();
                                this.$refs.hintDialog.close();
                            }
                        });
                } else {
                    this.$refs.hintDialog.close();
                }
            });
        },
        // 取消setDialog内部提示弹框 关闭内部弹窗
        cancleDialog() {
            this.$refs.hintDialog.close();
        },
        // 关闭setDialog和其内部弹窗
        confirmDialog() {
            this.$refs.hintDialog.close();
            this.$refs.setDialog.close();
        },
        // 关闭setDialog和其内部弹窗 并保存数据
        confirmAndSave() {
            // 需保存数据操作
            // this.confirmDialog();
            this.saveSetDialog();
        },
        // 点击编辑  弹窗并处理数据
        editCharging(row) {
            this.$refs.setDialog.open();
            this.setDialog.type = "edit";
            this.setDialog.projId = row.projId;
            let setDialogForm = this.setDialog.form;
            for (var key in setDialogForm) {
                if (key.includes("type")) {
                    setDialogForm[key] = "0";
                } else {
                    setDialogForm[key] = row[key];
                }
            }
            setDialogForm.ids = [row.payConditionId];
            setDialogForm.payConditionId = row.payConditionId;
            this.handleChangeFaculty(row.faculty, "edit");
            this.setDialog.professionFrom = row.profession.length>0? row.profession.split(","):[];
            // this.getSum();
            this.changeClick(row.lengthSchooling)
        },
        // 点击复制 在校应缴费信息
        copyCharging() {
            let length = this.chargingList.selectItems.length;
            if (length && length !== 1)
                this.$message({
                    message: "仅可选中一条记录进行复制",
                    type: "warning"
                });
            else if (!length)
                this.$message({
                    message: "请先选中需复制的应收费设置",
                    type: "warning"
                });
            else if (length && length === 1) {
                let copyData = this.chargingList.selectItems[0];
                this.setDialog.type = "copy";
                this.$refs.setDialog.open();
                this.setDialog.projId = copyData.projId;
                let setDialogForm = this.setDialog.form;
                for (var key in setDialogForm) {
                    if (!key.includes("type")) {
                        setDialogForm[key] = copyData[key];
                    }
                }
                this.handleChangeFaculty(copyData.faculty, "copy");
                this.setDialog.professionFrom = copyData.profession.length>0?copyData.profession.split(","):[];
                this.getSum();
            }
        },
        // 点击删除按钮，弹出删除提示框并存储删除的数据
        deleteCharging(row) {
            this.$refs.deleteDialog.open();
            this.deleteDialog.data = row;
        },
        // 取消删除
        cancleDelete() {
            this.$refs.deleteDialog.close();
            this.deleteDialog.data = null;
        },
        // 确认删除
        confirmDelete() {
            // 删除接口调用
            let data = this.deleteDialog.data;
            if (data && data.payConditionId) {
                API.deletePayConfig({ ids: [data.payConditionId] }).then(
                    res => {
                        if (res.code === 200) {
                            this.deleteDialog.data = null;
                            this.$message({
                                type: "success",
                                message: "删除成功!"
                            });
                            this.getChargingSetList();
                        }
                    }
                );
            }
            this.$refs.deleteDialog.close();
        },
        // 重置
        reset() {
            let query = this.query;
            for (var key in query) {
                if (key.includes("pageNum_")) {
                    query[key] = 1;
                } else if (key.includes("pageSize_")) {
                    query[key] = 20;
                } else {
                    query[key] = "";
                }
            }
            // 重置多选下拉数组
            let multipleQuery = this.multipleQuery;
            for (var i in multipleQuery) {
                multipleQuery[i] = [];
            }
            this.options.profession = [];
            this.getChargingSetList();
        },
        // 筛选
        filterCondition() {
            this.query.pageNum_ = 1;
            this.getChargingSetList();
        },
        // table 数据选中
        handleSelectionChange(val) {
            this.chargingList.selectItems = val;
        },
        // 初始化名单
        initList() {
            let length = this.chargingList.selectItems.length;
            if (!length)
                this.$message({
                    message: "请先选中需初始化名单的应收费设置",
                    type: "warning"
                });
            else {
                API.initPayment(this.chargingList.selectItems).then(res => {
                    if (res.code === 200) {
                        this.$message({
                            type: "success",
                            message: `成功，已添加 ${res.data} 名学生至缴费名单`
                        });
                        // 清空选中数据
                        this.$refs.chargingTable.clearSelection();
                    }
                });
            }
        },
        // 在线应收费列表
        getChargingSetList() {
            this.query.faculty = this.multipleQuery.faculty.join(",");
            this.query.profession = this.multipleQuery.profession.join(",");
            this.query.trainingLevel = this.multipleQuery.trainingLevel.join(
                ","
            );
            this.query.trainingCategory = this.multipleQuery.trainingCategory.join(
                ","
            );
            this.query.lengthSchooling = this.multipleQuery.lengthSchooling.join(
                ","
            );
            this.query.projId = this.currentManageDptId || "";
            this.chargingList.data = [];
            this.chargingList.total = 0;
            API.payConfigList(this.query).then(res => {
                if (res.code === 200 && res.data) {
                    // 处理数据
                    let arr = [];
                    let list = res.data.list;
                    arr = list.map(l => {
                        let obj = l;
                        let length = obj.length;
                        if (length > 1) {
                            let professionI18n = "";
                            let profession = "";
                            obj.forEach((o, i) => {
                                if (length - 1 == i) {
                                    profession += o.profession;
                                    professionI18n += o.professionI18n;
                                } else {
                                    profession += o.profession + ",";
                                    professionI18n +=
                                        o.professionI18n + ",";
                                }
                            });
                            obj[0].professionI18n = professionI18n;
                            obj[0].profession = profession;
                        }
                        return obj[0];
                    });
                    this.chargingList.data = arr;
                    this.chargingList.total = res.data.total_;
                    this.query.pageNum_ = res.data.pageNum_;
                }
            });
        },
        pageChange(val) {
            this.query.pageNum_ = val.pageNum;
            this.query.pageSize_ = val.pageSize;
            this.getChargingSetList();
        },
        changeClick(val) {
            // this.getSum()
            let formData = this.setDialog.form;
            for(let key in this.setDialog.form) {
                for(let i = val*2+1; i < 17 ; i++) {
                    this.setDialog.form['semester' + i] = null
                }
            }
            
            let semesterArr = [];
            switch (val) {
                case '0.5':
                    semesterArr.push(formData.semester1);
                break;
                case '1':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                break;
                case '1.5':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                break;
                case '2':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                break;
                case '2.5':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                break;
                case '3':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                break;
                case '3.5':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                    semesterArr.push(formData.semester7);
                break;
                case '4':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                    semesterArr.push(formData.semester7);
                    semesterArr.push(formData.semester8);
                break;
                case '4.5':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                    semesterArr.push(formData.semester7);
                    semesterArr.push(formData.semester8);
                    semesterArr.push(formData.semester9);
                break;
                case '5':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                    semesterArr.push(formData.semester7);
                    semesterArr.push(formData.semester8);
                    semesterArr.push(formData.semester9);
                    semesterArr.push(formData.semester10);
                break;
                case '5.5':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                    semesterArr.push(formData.semester7);
                    semesterArr.push(formData.semester8);
                    semesterArr.push(formData.semester9);
                    semesterArr.push(formData.semester10);
                    semesterArr.push(formData.semester11);
                break;
                case '6':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                    semesterArr.push(formData.semester7);
                    semesterArr.push(formData.semester8);
                    semesterArr.push(formData.semester9);
                    semesterArr.push(formData.semester11);
                    semesterArr.push(formData.semester12);
                break;
                case '7':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                    semesterArr.push(formData.semester7);
                    semesterArr.push(formData.semester8);
                    semesterArr.push(formData.semester9);
                    semesterArr.push(formData.semester11);
                    semesterArr.push(formData.semester12);
                    semesterArr.push(formData.semester13);
                    semesterArr.push(formData.semester14);
                break;
                case '8':
                    semesterArr.push(formData.semester1);
                    semesterArr.push(formData.semester2);
                    semesterArr.push(formData.semester3);
                    semesterArr.push(formData.semester4);
                    semesterArr.push(formData.semester5);
                    semesterArr.push(formData.semester6);
                    semesterArr.push(formData.semester7);
                    semesterArr.push(formData.semester8);
                    semesterArr.push(formData.semester9);
                    semesterArr.push(formData.semester11);
                    semesterArr.push(formData.semester12);
                    semesterArr.push(formData.semester13);
                    semesterArr.push(formData.semester14);
                    semesterArr.push(formData.semester15);
                    semesterArr.push(formData.semester16);
                break;
                default:
                    break;
            }
            let sum = 0;
            this.setDialog.form.sum = 0;
            sum = semesterArr.reduce((pre, curr, index) => {
                sum = pre + +curr;
                return sum;
            }, sum);
            sum = sum.toFixed(2);
            this.setDialog.form.sum = sum
        },
        getSum1() {},
        // 计算总应缴费用
        getSum() {
            let formData = this.setDialog.form;
            let semesterArr = [];
            for (var key in formData) {
                if (key.includes("semester") && formData[key]) {
                    semesterArr.push(formData[key]);
                }
            }
            let sum = 0;
            sum = semesterArr.reduce((pre, curr, index) => {
                sum = pre + +curr;
                return sum;
            }, sum);
            sum = sum.toFixed(2);
            this.$set(this.setDialog.form, "sum", sum);
        },
        // 获取缴费简称条件
        getPayConditionName(val) {
            if (val) {
                this.options.payConditionId = [];
                API.payConditionName(val).then(res => {
                    if (res.code === 200 && res.data) {
                        res.data.forEach(item => {
                            this.options.payConditionId.push({
                                label: item.name,
                                value: item.id
                            });
                        });
                    }
                });
            } else {
                this.options.payConditionId = [];
            }
        },
        // 清空时清除缴费条件简称下拉框
        clearOptions() {
            this.options.payConditionId = [];
        }
    },
    computed: {
        currentUser() {
            if (this.$store.state.session.user) {
                return this.$store.state.session.user;
            }
            return JSON.parse(localStorage.getItem("user"));
        },
        mockUser() {
            if (this.$store.state.session.mockUser) {
                return this.$store.state.session.mockUser;
            }
            return JSON.parse(localStorage.getItem("sessiondata")).mockUser;
        }
    }
};
</script>
<style lang="scss" scoped>
// .charging-set {
// }
</style>
<!-- 覆盖element样式 -->
<style lang="scss">
.charging-set {
    .el-input-number.is-without-controls .el-input__inner {
        padding-right: 8px !important;
        padding-left: 8px !important;
        text-align: left;
    }
}
</style>
